package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"os"
	"strings"
)

func init_router() {
	r := gin.Default()
	r.GET("/yml", showYmlCfg)
	_ = r.Run() //port：8080
}

func showYmlCfg(context *gin.Context) {

}

func main() {
	viper.SetEnvPrefix("core")
	viper.AutomaticEnv()
	replacer := strings.NewReplacer(".", "_")
	viper.SetEnvKeyReplacer(replacer)
	viper.SetConfigName("core")
	viper.AddConfigPath("./")

	viper.Set("spring.redis.database", 4) //set的优先级最高，注释这句，spring.redis.database的结果为配置值： 2
	//load 配置
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println(fmt.Errorf("Fatal error when reading %s config file:%s", "core", err))
		os.Exit(1)
	}

	environment := viper.GetBool("security.enabled")
	fmt.Println("security.enabled:", environment)

	fullstate := viper.GetString("statetransfer.timeout.fullstate")
	fmt.Println("statetransfer.timeout.fullstate:", fullstate)

	abcdValue := viper.GetString("peer.abcd")
	fmt.Println("peer.abcd:", abcdValue)

	fmt.Println(viper.GetStringSlice("hosts"))
	fmt.Println(viper.GetInt("spring.redis.port"))

	fmt.Println(viper.GetInt("spring.redis.database"))

}
